program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  arr=array of integer;
var
  mass: array of arr;
  col: array of integer;
  N, a, i, j: integer;
  fin, fout: textfile;
begin
  assignfile(fin, 'input.txt');
  reset(fin);
  assignfile(fout, 'output.txt');
  rewrite(fout);
  readln(fin, N);
  setlength(mass, N);
  for i:=0 to N-1 do
    setlength(mass[i], N);
  for i:=0 to N-1 do
    for j:=0 to N-1 do
      read(fin, mass[i,j]);
  setlength(col, N);
  for i:=0 to N-1 do
    read(fin, col[i]);
  a:=0;

  for i:=0 to n-1 do
    for j:=0 to n-1 do
      if (mass[i, j]=1) and (col[i]<>col[j]) then
        a:=a+1;
  a:=a div 2;
  writeln(fout, a);
  closefile(fin);
  closefile(fout);
end.
 
